<?php
/**
 * Created by PhpStorm.
 * User: mhx
 * Date: 17-3-29
 * Time: 下午1:28
 */
class commonController extends baseController{
    public function __construct()
    {
        parent::__construct();
    }


    //由于表改了，这段暂时没用
    public function autogetcityid(){
     /*$aa=  $this->getcityid('汕头');
        print_r($aa);die;*/

     return null;
        /*$update = array();
        $data = model('mamuseum')->select('cityid=0');
        for($i = 0;isset($data[$i]);$i++){
            $cityid = $this->getcityid($data[$i]['city']);
            if($cityid==false){continue;}
            if($data[$i]['city'] != $cityid['name']){
                $update['city'] = $cityid['name'];
            }
            $update['cityid'] = $cityid['id'];
            model('mamuseum')->update('id="'.$data[$i]['id'].'"',$update);

        }
        die;*/
    }

    //城市id
    public function getcityid($city){

        if($city==null){
            return false;
        }else{
            $data = model('city')->select();

            for($i=0;isset($data[$i]);$i++){
                $pos = mb_strpos($data[$i]['name'],$city);
                if($pos !== false){
                    return $data[$i];
                }
            }
            return false;

        }



    }
    //省份id省id其实是不需要的，查pid
    public function getprovinceid($province){

        if($province ==null){
            return null;
        }else{
            $data = model('city')->find('name="'.$province.'"');
            print_r($data);die;
        }

    }

    //转表
    public function changetable(){
        $data = model('mamuseum')->select();
        for($i = 0;isset($data[$i]);$i++){
//            print_r($data[$i]);die;
            $info = array();
            if($data[$i]['name']!=''){
                $info['apellation'] = str_replace('"','',$data[$i]['name']);
            }else{
                $info['apellation'] = '';
            }
            if($data[$i]['imagepath']!=''){
                $info['logo'] = $data[$i]['imagepath'];
            }else{
                $info['logo'] = '';
            }
            if($data[$i]['shopkeeper']!=''){
                $info['corporation'] = $data[$i]['shopkeeper'];
            }else{
                $info['corporation'] = '';
            }
            if($data[$i]['address']!=''){
                $info['address'] = $data[$i]['address'];
            }else{
                $info['address'] = '';
            }
            if($data[$i]['phone']!=''){
                $info['tel'] = $data[$i]['phone'];
            }else{
                $info['tel'] = '';
            }
            if($data[$i]['']!=''){
                $info['fax'] = $data[$i][''];
            }else{
                $info['fax'] = '';
            }
            if($data[$i]['mail']!=''){
                $info['email'] = $data[$i]['mail'];
            }else{
                $info['email'] = '';
            }
            if($data[$i]['url']!=''){
                $info['website'] = $data[$i]['url'];
            }else{
                $info['website'] = '';
            }
            if($data[$i]['introduction']!=''){
                $info['about'] = $data[$i]['introduction'];
            }else{
                $info['about'] = '';
            }
            if($data[$i]['project']!=''){
                $info['business'] = $data[$i]['project'];
            }else{
                $info['business'] = '';
            }
            if($data[$i]['cityid']!=''){
                $info['city'] = $data[$i]['cityid'];
            }else{
                $info['city'] = '';
            }
            if($data[$i]['longitude']!=''){
                $info['longitude'] = $data[$i]['longitude'];
            }else{
                $info['longitude'] = '';
            }if($data[$i]['latitude']!=''){
                $info['latitude'] = $data[$i]['latitude'];
            }else{
                $info['latitude'] = '';
            }
            $ret = model('companies')->find('apellation="'.$info['apellation'].'"');
            if($ret == false){
                model('companies')->insert($info);
            }


        }
        die;
    }
}


